﻿using Code;
using FluorineFx.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Serialize
{
    class Program : SerializeCode
    {

        /// <summary>
        /// 序列化 JSON
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {


            //实体类 
            ChildrenModel model = new ChildrenModel();
            model.Name = "一级节点";
            model.Children = new List<ChildrenModel>() { new ChildrenModel() };
            model.Children[0].Name = "N级节点";
            model.Children[0].Children = new List<ChildrenModel>() { new ChildrenModel() };
            model.Children[0].Children[0].Name = "沐光";
            model.Children[0].Children[0].Age = 25;
            model.Children[0].Children[0].PassWord = "E10ADC3949BA59ABBE56E057F20F883E";
            model.Children[0].Children[0].CreateTime = DateTime.Now;
            model.Children[0].Children[0].IsEnd = true;

            //JavaScriptObject 形式
            JavaScriptObject jsonObj = new JavaScriptObject()
            {
                {"Name","一级节点"},
                {"Children",new JavaScriptArray(){new JavaScriptObject(){
                     {"Name","N级节点"},
                     {"Children",new JavaScriptArray(){new JavaScriptObject(){
                            {"Name","沐光"},
                            {"Age",25},
                            {"PassWord","E10ADC3949BA59ABBE56E057F20F883E"},
                            {"CreateTime", DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss")},
                            {"IsEnd",true}
                     }}}
                }}}
            };
            //Dictionary形式
            Dictionary<string, object> JsonDic = new Dictionary<string, object>()
            {
                {"Name","一级节点"},
                {"Children",new List<Dictionary<string, object>>(){new Dictionary<string, object>(){
                     {"Name","N级节点"},
                     {"Children",new List<Dictionary<string, object>>(){new Dictionary<string, object>(){
                            {"Name","沐光"},
                            {"Age",25},
                            {"PassWord","E10ADC3949BA59ABBE56E057F20F883E"},
                            {"CreateTime", DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss")},
                            {"IsEnd",true}
                     }}}
                }}}
            };

            for (int i = 0; i < 20; i++)
            {
                GC.Collect();
                Console.WriteLine("////////////////////////////////////////////////////////////");
                Console.WriteLine("/////////////////序列化回车开始测试" + (i + 1) + "////////////////////////");
                Console.WriteLine("////////////////////////////////////////////////////////////");
                Console.ReadLine();

                Console.WriteLine("//NET系统类 序列化 实体类");
                DataContractJsonModel(model);

                Console.WriteLine("//优化NET系统类 序列化 实体类");
                DataContractJsonModelSpeed(model);

                Console.WriteLine("//NET系统类 序列化 实体类");
                DataContractJsonModel(model);

                Console.WriteLine("------------------------------------" + Environment.NewLine);

                Console.WriteLine("//NET Web JavaScript系统类 序列化 实体类");
                WebJavaScriptJsonModelSpeed(model);

                Console.WriteLine("//NET Web JavaScript系统类 序列化 JavaScriptObject");
                WebJavaScriptJsonModelSpeed(jsonObj);

                Console.WriteLine("//NET Web JavaScript系统类 序列化 Dictionary");
                WebJavaScriptJsonModelSpeed(JsonDic);

                Console.WriteLine("------------------------------------" + Environment.NewLine);

                Console.WriteLine("//Newtonsoft.Json 序列化 实体类");
                NewtonsoftJsonDictionary(model);

                Console.WriteLine("//Newtonsoft.Json 去NULL序列化 实体类");
                NewtonsoftJsonModel(model);

                Console.WriteLine("//Newtonsoft.Json 序列化 JavaScriptObject ");
                NewtonsoftJsonDictionary(jsonObj);

                Console.WriteLine("//Newtonsoft.Json 序列化 Dictionary");
                NewtonsoftJsonDictionary(JsonDic);


                Console.WriteLine("------------------------------------" + Environment.NewLine);


                Console.WriteLine("//FluorineFx 序列化 实体类 ");
                FluorineFxJsonModel(model);

                Console.WriteLine("//FluorineFx 序列化 JavaScriptObject ");
                FluorineFxJsonDictionary(jsonObj);

                Console.WriteLine("//FluorineFx 序列化 Dictionary ");
                string json= FluorineFxJsonDictionary(JsonDic);

                Console.WriteLine("------------------------------------2进制序列化" + Environment.NewLine);

                //Console.WriteLine("//FluorineFx AMF3 序列化 String ");
                //FluorineFxAMF3String(json);

                //Console.WriteLine("//FluorineFx AMF3 序列化 Byte ");
                //FluorineFxAMF3Bytes(Encoding.UTF8.GetBytes(json));

                //Console.WriteLine("//FluorineFx AMF3 序列化 实体类 ");
                //FluorineFxAMF3Object(model);

                //Console.WriteLine("//FluorineFx AMF3 序列化 JavaScriptObject ");
                //FluorineFxAMF3Object(jsonObj);

                //Console.WriteLine("//FluorineFx AMF3 序列化 Dictionary ");
                //FluorineFxAMF3Object(JsonDic);

                //Console.WriteLine("//NET类库BinaryFormatter 序列化 Dictionary ");
                //BinaryFormatter(JsonDic);

                //Console.WriteLine("//NET类库BinaryFormatter 序列化 实体类 ");
                //BinaryFormatter(model);

                //Console.WriteLine("//FluorineFx AMF3 反序列化 Dictionary ");
                //FluorineFxDictionaryAMF3();

                Console.ReadLine();
            }
        }
    }

}
